Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

225
Vistas
Script Produces "Uncaught TypeError: Cannot read properties of null (reading 'scrollHeight')" When Iframe is Reloaded

I added the highlighted script to my PHP page's header to automatically adjust iframe size to iframe contents; the script is activated w/ <script>sizeit("#frame_id");</script>, and the results are as expected / it works well.

However, on iframe reload (w/ a "right-click / Reload iframe" selection within the iframe) the script produces the following error: "Uncaught TypeError: Cannot read properties of null (reading 'scrollHeight')"

It seems scrollHeight isn't available on iframe reload.

<script>
function sizeit(id){
    let iframe = document.querySelector(id);

    iframe.addEventListener('load', function() {
        setInterval(function() {
            iframe.style.height = iframe.contentDocument.body.scrollHeight + 10 + 'px';
            iframe.style.width = 100 + '%';
        });
    });
}
</script>

Any thoughts on how to resolve this? The error message does not appear when the entire page is reloaded, only when an iframe is reloaded.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda